<include file="__THEME__/admin_header" />
<div id="container" class="so_main">
  <div class="page_tit"><div class="right"><neq name="back_id" value="-1"><a href="{:U('admin/Config/area',array('pid'=>$back_id))}" class="btn_a"><span>返回</span></a></neq></div>地区管理</div>
  <div class="Toolbar_inbox">
    
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加地区</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除地区</span></a>
  </div>
  
  <div class="list">
  <table id="area_list" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">地区名称</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="area">
      <tr overstyle='on' id="area_{$vo.area_id}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.area_id}"></td>
        <td>{$vo.area_id}</td>
        <td><div style="float:left"><a href="{:U('admin/Config/area',array('pid'=>$vo['area_id']))}" id="area_title_{$vo.area_id}">{$vo.title}</a></div></td>
        <td>
            <a href="javascript:void(0);" onclick="edit({$vo['area_id']});">编辑</a> 
            <a href="{:U('admin/Config/area',array('pid'=>$vo['area_id']))}">下级管理</a>
            <a href="javascript:void(0);" onclick="del({$vo['area_id']});">删除</a>  
        </td>
      </tr>
  </volist>
  </table>

  </div>
  <div class="Toolbar_inbox">
    <neq name="back_id" value="-1"><a href="{:U('admin/Config/area',array('pid'=>$back_id))}" class="btn_a"><span>返回</span></a></neq>
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加地区</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除地区</span></a>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择用户的ID数组
    function getChecked() {
        var gids = new Array();
        $.each($('input:checked'), function(i, n){
            gids.push( $(n).val() );
        });
        return gids;
    }

    //添加地区
    function add() {
        ui.box.load("{:U('admin/Config/addArea',array('pid'=>$pid))}", '添加地区');
    }
    
    //编辑地区
    function edit(area_id) {
        ui.box.load("{:U('admin/Config/editArea')}&area_id="+area_id, '编辑地区');
    }
    
    //删除地区
    function del(aid) {
        aid = aid ? aid : getChecked();
        aid = aid.toString();
        if(aid == '' || getLength(aid)<1){
          ui.error('请选择地区');
          return false;
        } 
        if(confirm('确定删除选中地区？')){
          //提交删除
          $.post("{:U('admin/Config/doDeleteArea')}", {ids:aid}, function(res){
  	        if(res == '1') {
  		        aid = aid.split(',');
  		        $.each(aid, function(i,n){
  		            $('#area_'+n).remove();
  		        });
  	            ui.success('删除成功');
  	        }else {
  	        	ui.error('删除失败');
  	        }
          });
      }
    }
</script>

<include file="__THEME__/admin_footer" />